//
//  main.cpp
//  StackAdapterStudy
//
//  Created by huge on 2021/6/23.
//  Copyright © 2021 huge. All rights reserved.
//

#include <iostream>
#include <list>
#include <stack>
#include <queue>
#include <iterator>     // std::next

using namespace std;

//自定义二元谓词函数，作为 find_first_of() 函数的匹配规则
bool mycomp(int c1, int c2) {
    return (c2 % c1 == 0);
}
//以函数对象的形式定义一个 find_first_of() 函数的匹配规则
class mycomp2 {
public:
    bool operator()(const int& c1, const int& c2) {
        return (c2 % c1 == 0);
    }
};
int find_first_of_main() {
    char url[] = "http://c.biancheng.net/stl/";
    char ch[] = "stl";
    //调用第一种语法格式，找到 url 中和 "stl" 任一字符相同的第一个字符
    char *it = find_first_of(url, url + 27, ch, ch + 4);
    if (it != url + 27) {
        cout << "*it = " << *it << '\n' << it << '\n';
    }
//    vector<int> myvector{ 5,7,3,9 };
//    int inter[] = { 4,6,8 };
//    //调用第二种语法格式，找到 myvector 容器中和 3、5、7 任一元素有 c2%c1=0 关系的第一个元素
//    vector<int>::iterator iter = find_first_of(myvector.begin(), myvector.end(), inter, inter + 3, mycomp2());
//    if (iter != myvector.end()) {
//        cout << "*iter = " << *iter;
//    }
    return 0;
}


void reverseIterTest(){
    std::list<int>values{1,2,3};
    std::reverse_iterator<std::list<int>::iterator> begin = values.rbegin();
    std::reverse_iterator<std::list<int>::iterator> end = values.rend();
    
    while (begin!=end) {
        std::cout << *begin << "\n";
        ++begin;
    }
}
void testQueue(){
    std::deque<int>myDeque{1,2,3};
    std::queue<int,std::deque<int>>myQueue(myDeque);
    
    std::cout << "queue size: " << myQueue.size()
                << "\t"<<myQueue.front() << "\t" <<myQueue.back() << "\n";
    
    myQueue.emplace(666);
    std::cout << "queue size: " << myQueue.size()
    << "\t"<<myQueue.front() << "\t" <<myQueue.back() << "\n";
    
    return;
}

int main(int argc, const char * argv[]) {
    // insert code here...
//    testQueue();
    reverseIterTest();
    
    std::list<int> list1{1,2,3};
    std::stack<int,std::list<int>>myStack(list1);
    
    myStack.push(4);
    myStack.pop();
    std::cout <<"stack size: " << myStack.size() <<"\t"<<myStack.top()<<"\t"<<myStack.empty()<<"\n";
    while (!myStack.empty()) {
        std::cout << myStack.top()<<"\t";
        myStack.pop();
    }
    std::cout << "Hello, World!\n";
    
//    //创建并初始化一个 list 容器
//    std::list<int> mylist{ 1,2,3,4,5 };
//    std::list<int>::iterator it = mylist.end();
//    //获取一个距离 it 迭代器 2 个元素的迭代器，由于 2 为正数，newit 位于 it 左侧
//    auto newit = prev(it, 2);
//    cout << "prev(it, 2) = " << *newit << endl;
//
//    //n为负数，newit 位于 it 右侧
//    it = mylist.begin();
//    newit = prev(it, -2);
//    cout << "prev(it, -2) = " << *newit;
//    return 0;

    find_first_of_main();
    return 0;
}

